package asteroids.model.programs.statements;

import exception.StopActionClassException;
import asteroids.model.programs.Expression;
import asteroids.model.programs.Program;

public class AssignmentStatement extends Statement {
	
	public AssignmentStatement(String variable, Expression<?> e){
		this.variable=variable;
		this.assignment=e;
	}
	
	private String variable;
	private Expression<?> assignment;

	@SuppressWarnings("unchecked")
	@Override
	public void execute(Program program) throws StopActionClassException {
		if(!isExecuted()){
		program.getGlobals().get(variable).setValue(assignment.getValue(program));
		setExecuted();
		}
	}

	@Override
	public void reset() {
		setUnexecuted();
	}

}
